package saee.dao;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Query;

import saee.modelo.Vaga;
import saee.modelo.VagaCurso;
import saee.util.JPAUtil;

public class VagaCursoDAO extends GenericDAO {

	public VagaCurso buscaPeloId(Integer id) {

		em = new JPAUtil().getEntityManager();
		em.getTransaction().begin();
		
		VagaCurso vagaCurso = new VagaCurso();
		try {
			vagaCurso = em.find(VagaCurso.class, id);
			
		} catch (Exception e) {
			e.printStackTrace();
			em.getTransaction().rollback();
		} finally {
			em.close();
		}
		return vagaCurso;
	}
	
	@SuppressWarnings("unchecked")
	public List<VagaCurso> listarTodos(Vaga vaga) {
		em = new JPAUtil().getEntityManager();
		boolean r = false;
		List<VagaCurso> vagaCursos = new ArrayList<VagaCurso>();
		try {
			em.getTransaction().begin();
			Query query = em.createQuery("Select a from VagaCurso a where a.vaga=:vaga");
			query.setParameter("vaga", vaga);
			vagaCursos = query.getResultList();
		} catch (Exception e) {
			e.printStackTrace();
			em.getTransaction().rollback();
		} finally {
			em.close();
			// factory.close();
		}

		return vagaCursos;

	}

}
